﻿namespace Zhao.Arena.Utility.RegisterExt
{
    /// <summary>
    /// 静态扩展方法
    /// </summary>
    public static class CorsServiceExtension
    {
        /// <summary>
        /// 配置支持所有API都允许跨越
        /// </summary>
        /// <param name="builder"></param>
        public static void CorsDomainsPolicy(this WebApplicationBuilder builder)
        {
            builder.Services.AddCors(option =>
            {
                //所有的Api都支持跨越
                option.AddPolicy("AllCorsDomainsPolicy", coresbuilder =>
                {
                    coresbuilder.AllowAnyOrigin()
                    .AllowAnyHeader()
                    .AllowAnyMethod();
                });
            });
        }
        /// <summary>
        /// 配置跨越服务生效
        /// </summary>
        /// <param name="app"></param>
        public static void UseCorsDomainsPolicy(this WebApplication app) => app.UseCors("AllCorsDomainsPolicy");

    }
}
